cat('Creating Table A26 \n\n')

dat = read.csv('TableA26_data.csv')
dat.uo = dat[dat$uo.non.uo == 'uo',]
dat.sec = dat[dat$uo.non.uo != 'uo',]

##formulas specific to cooperation games
use.formula = as.formula(paste('public.ingroup.preference ~ ',master.formula,sep = ''))
use.formula.interactions = as.formula(paste('public.ingroup.preference ~ ',master.formula.interactions,sep = ''))
use.formula.reduced = as.formula(paste('public.ingroup.preference ~ ',master.formula.reduced,sep = ''))


##UO
##regressions
reg.uo.pub = lm(use.formula, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub, dat.uo$index.city)
reg.uo.pub$se = clustered.se

reg.uo.pub.reduced = lm(use.formula.reduced, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.reduced, dat.uo$index.city)
reg.uo.pub.reduced$se = clustered.se

reg.uo.pub.interactions = lm(use.formula.interactions, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.interactions, dat.uo$index.city)
reg.uo.pub.interactions$se = clustered.se


##Secular
##regressions
reg.sec.pub = lm(use.formula, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub, dat.sec$index.city)
reg.sec.pub$se = clustered.se

reg.sec.pub.reduced = lm(use.formula.reduced, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.reduced, dat.sec$index.city)
reg.sec.pub.reduced$se = clustered.se

reg.sec.pub.interactions = lm(use.formula.interactions, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.interactions, dat.sec$index.city)
reg.sec.pub.interactions$se = clustered.se

outtable = apsrtable(reg.uo.pub.reduced,
                     reg.uo.pub,
                     reg.uo.pub.interactions,
                     reg.sec.pub.reduced,
                     reg.sec.pub,
                     reg.sec.pub.interactions,
                     Sweave = T,
                     coef.names = coef.names,
                     stars = 'default',
                     model.names = c('UO','UO','UO','Non UO','Non UO','Non UO'),
                     notes = ''
                    )
writeLines(
  outtable, 'TableA26.tex')

